package com.jushu.storbox.database;

import java.util.HashMap;
import java.util.List;

import com.jushu.storbox.entities.FileFolderInfo;
import com.jushu.storbox.entities.FileInfo;
import com.huawei.sharedrive.sdk.android.modelV2.response.FileInfoResponseV2;

public interface IFileDao extends IBaseDao {

	public final static String TABLE_NAME = "tb_file_list";
	
	public final static String CURRENT_USER_ID = "current_user_jd";
	
	public final static String TABLE_COMMAND = "Create table " + TABLE_NAME + "("
			+ FIELD_ID + " integer,"
			+ id + " text," 
			+ owner_by + " text," 
			+ file_name + " text,"
			+ is_file + " integer," 
			+ parent_folder_id + " text,"
			+ file_md5 + " text," 
			+ file_size + " integer," 
			+ server_ctime + " integer," 
			+ server_mtime + " integer," 
			+ local_path + " text," 
			+ client_ctime + " integer," 
			+ client_mtime + " integer," 
			+ content_sync_status + " integer,"
			+ static_status + " text,"
			+ trans_status + " integer," 
			+ trans_status_ref_cnt + " integer," 
			+ is_exist + " integer," 
			+ file_true_md5 + " text," 
			+ local_operation_time + " integer," 
			+ local_last_modify_time + " integer,"
			+ last_refresh_time + " integer," 
			+ description + " text,"
			+ file_etag + " text," 
			+ file_sha1 + " text,a" //?a
			+ file_version + " text," 
			+ isshare + " text," 
			+ isshare_link + " text,"
			+ isencrypt + " text," 
			+ isSync + " integer," 
			+ fileIcon + " text,"
			+ CURRENT_USER_ID +" text,"
			+ "CONSTRAINT pk_tb_file_list PRIMARY KEY ("+id+","+owner_by +","+CURRENT_USER_ID+")"
			+")";
	
	public long insertFile(FileInfoResponseV2 fileInfo);
	
	public long insertFile(FileFolderInfo fileInfo);
	
	public void updateFile(FileInfoResponseV2 fileInfoResponse,
			boolean resetFileDownloadState, boolean syncIdentity);

	public void update(FileFolderInfo fileInfo);
	
	public void updateLocalPath(String ownerId, String fileId, String localPath);
	
	public void updateLocalPath(FileFolderInfo file, String localPath);
	
	public void updateLocalPath(FileInfoResponseV2 serverFile, String localPath);
	
	public void updateTransStatus(FileFolderInfo file, int status);
	
	public void updateTransStatus(FileInfoResponseV2 serverFile, int status);
	
	public void updateFileIdentify(FileFolderInfo file, String identify);

	public int getTransStatus(FileFolderInfo file);

	public void updateSyncStatus(FileInfoResponseV2 serverNode, int syncStatus);
	
	public void updateSyncStatus(String ownerId, String fileId, int syncStatus);
	
	public void updateSyncStatus(FileFolderInfo file, int syncStatus);

	public long getLastUpdateTime(FileFolderInfo file);

	public void updateLastUpdateTime(FileFolderInfo file);

	/** update sync state</br>
	 * call {@link FileFolderInfo#setContentSyncState(int)} before this*/
	public void updateLocalSaveState(FileFolderInfo file);
	
	public void rename(FileFolderInfo file, String name);

	/**
	 * @param context
	 * @param parentID
	 * @param fileID
	 */
	public void move(FileFolderInfo file, FileFolderInfo folder);

	public void delete(FileFolderInfo file);

	public void deleteAll();

	public void setShareLink(FileFolderInfo file, boolean isShareLink);

	public void cleanCatch();

	public int addIfNotExist(FileInfoResponseV2 fileInfo);
	
	public FileInfo getFile(FileInfoResponseV2 serverNode);
	
	public FileInfo getFile(FileFolderInfo serverNode);
	
	public FileInfo getFile(String ownerId, String fileId);

	public List<FileInfo> getFileList(FileFolderInfo folder);

	public List<FileInfo> getFileListPage(String ownerId, String folderId, int flag);

	public List<FileInfo> getFileListPage(String ownerId, String folderId, int flag, String des, String orderBy);
	
	public List<FileInfo> getFileListByPage(String ownerId, String folderId, int pageNo, int number, String des, String orderBy);

	public HashMap<String, FileInfo> getMappedFileDatas(FileFolderInfo folder);
	
	public HashMap<String, FileInfo> getMappedFileDatas(String ownerId, String folderId);

	public List<FileInfo> getFileList(String ownerId, String parentID);

	public void updateTransStatus(String ownerId, String id, int trans_status);

	public List<FileInfo> getSearchFileList(String ownerId, String fileName);

	public void rename(FileInfoResponseV2 fileInfoResponse, String name);
	
	public void rename(String ownerId, String folderId, long modifyedTime, String name) ;

	public void syncFileInfoToLocal(FileFolderInfo info);
}